package cn.manyufun.myf.ui.common.Presenter;

import cn.manyufun.myf.R;
import cn.manyufun.myf.bean.ArticleListBean;
import cn.manyufun.myf.bean.FollowListBean;
import cn.manyufun.myf.bean.ReplyListBean;
import cn.manyufun.myf.common.baserx.RxSubscriber;
import cn.manyufun.myf.ui.common.contact.CommonListContract;

/**
 * @author Kevin Xiao
 * @date Create Date: 2018-03-01
 * @Description
 */
public class CommonListPresenter extends CommonListContract.Presenter {
    @Override
    public void getCommonListDataRequest(int pageIndex, int pageSize, final int type) {
        mRxManage.add(mModel.getCommonListData(pageIndex, pageSize, type)
                .subscribe(new RxSubscriber<FollowListBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(FollowListBean followListBean) {
                        mView.returnCommonListData(followListBean, type);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }

    @Override
    public void getComicsCommentListDataRequest(int pageIndex, int pageSize, final long comicsId) {
        mRxManage.add(mModel.getComicsCommentListData(pageIndex, pageSize, comicsId)
                .subscribe(new RxSubscriber<ReplyListBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(ReplyListBean replyListBean) {
                        mView.returnComicsCommentListData(replyListBean);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }

    @Override
    public void getArticleCommentListDataRequest(int pageIndex, int pageSize, final long articleID) {
        mRxManage.add(mModel.getArticleCommentListData(pageIndex, pageSize, articleID)
                .subscribe(new RxSubscriber<ReplyListBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(ReplyListBean replyListBean) {
                        mView.returnComicsCommentListData(replyListBean);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }

    @Override
    public void getComicArticleListDataRequest(int pageIndex, int pageSize, final long comicsId) {
        mRxManage.add(mModel.getComicArticleListData(pageIndex, pageSize, comicsId)
                .subscribe(new RxSubscriber<ArticleListBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(ArticleListBean articleListBean) {
                        mView.returnComicArticleListData(articleListBean);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }
}
